package com.yby.mall.product.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.yby.common.utils.PageUtils;
import com.yby.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yby.common.utils.Query;

import com.yby.mall.product.dao.SkuInfoDao;
import com.yby.mall.product.entity.SkuInfoEntity;
import com.yby.mall.product.service.SkuInfoService;
import org.springframework.util.StringUtils;


@Service("skuInfoService")
public class SkuInfoServiceImpl extends ServiceImpl<SkuInfoDao, SkuInfoEntity> implements SkuInfoService {

    @Autowired
    private SkuInfoDao skuInfoDao;

    @Override
    public R queryPage(Integer page, Integer limit, String key, Long catelogId, Long brandId, BigDecimal min, BigDecimal max) {
        PageHelper.startPage(page,limit);
        List<SkuInfoEntity> list = skuInfoDao.selectList(Wrappers.<SkuInfoEntity>lambdaQuery()
                .like(!StringUtils.isEmpty(key), SkuInfoEntity::getSkuName, key)
                .eq(!StringUtils.isEmpty(catelogId) && catelogId != 0, SkuInfoEntity::getCatalogId, catelogId)
                .eq( !StringUtils.isEmpty(brandId) && brandId != 0, SkuInfoEntity::getBrandId, brandId)
                .ge(!StringUtils.isEmpty(min) && (new BigDecimal("0").compareTo(min)) != 0, SkuInfoEntity::getPrice, min)
                .le(!StringUtils.isEmpty(max) && (new BigDecimal("0").compareTo(max)) != 0, SkuInfoEntity::getPrice, max)
        );
        return R.ok().put("page",PageUtils.restPage(list));
    }
}